package com.wenhai.leetcode.array;

/**
 *  https://leetcode-cn.com/problems/first-unique-character-in-a-string/
 *
 * @author wenhai
 * @date   2021/4/1
 */
public class _387字符串中的第一个唯一字符 {

    public int firstUniqChar(String s) {
        int[] table = new int[26];
        for (int i = 0; i < s.length(); i++) {
            table[s.charAt(i) - 'a']++;
        }

        for (int i = 0; i < s.length(); i++) {
            if (table[s.charAt(i) - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }

}
